var t = getApp();

Page({
    data: {
        form: {
            title: "",
            sku: "",
            thumb: "",
            thumb_url: [],
            content: "",
            describe: ""
        },
        showphone: !1,
        checkXy: !0,
        checkXy_show: !1,
        protocol: "",
        paramArr: [],
        param_title: [],
        param_value: [],
        uploadUrl: "upload.uploadPic",
        sectionOptions: [],
        newoptions: [],
        addressShow: !1,
        one: 0,
        two: 0,
        pickerValue: [ 0, 0, 0 ],
        selectedOptions3: []
    },
    onLoad: function(t) {
        t.good && (this.setData({
            "form.goods_id": t.good
        }), this.getInfo()), this.getAgreement(), this.getJson();
    },
    onClicksQ: function() {
        this.setData({
            checkXy_show: !1
        });
    },
    onClicks: function() {
        this.setData({
            checkXy_show: !0
        });
    },
    delThumb: function(t) {
        0 == t.currentTarget.id && this.setData({
            "form.thumb": ""
        });
    },
    delcontent: function(t) {
        0 == t.currentTarget.id && this.setData({
            "form.content": ""
        });
    },
    delthumb_url: function(t) {
        0 == t.currentTarget.id && this.setData({
            "form.thumb_url": ""
        });
    },
    Chooseinp: function() {
        this.setData({
            checkXy: !this.data.checkXy
        });
    },
    calshow: function() {
        this.setData({
            showphone: !1
        });
    },
    delShuxing: function(t) {
        console.log(t.currentTarget.dataset.ind);
        var a = t.currentTarget.dataset.ind;
        0 != a ? this.data.paramArr.splice(a, 1) : this.setData({
            paramArr: []
        });
    },
    pushAttr: function() {
        if (t._isTextEmpty(this.data.param_title)) wx.showToast({
            title: "请填写属性名",
            icon: "none",
            duration: 1e3
        }); else if (t._isTextEmpty(this.data.param_value)) wx.showToast({
            title: "请填写属性值",
            icon: "none",
            duration: 1e3
        }); else {
            var a = {
                attrname: this.data.param_value,
                attrvalue: this.data.param_title
            }, e = this.data.paramArr;
            e.push(a), this.setData({
                paramArr: e,
                showphone: !1
            });
        }
    },
    attrvalue: function(t) {
        this.setData({
            param_value: t.detail.value
        });
    },
    attrname: function(t) {
        this.setData({
            param_title: t.detail.value
        });
    },
    isCoverLayer: function(t) {
        this.setData({
            showphone: !1
        });
    },
    tapSx: function(t) {
        this.setData({
            showphone: !0,
            param_title: "",
            param_value: ""
        });
    },
    title: function(t) {
        this.setData({
            "form.title": t.detail.value
        });
    },
    sku: function(t) {
        this.setData({
            "form.sku": t.detail.value
        });
    },
    stock: function(t) {
        this.setData({
            "form.stock": t.detail.value
        });
    },
    remarkinp: function(t) {
        this.setData({
            "form.describe": t.detail.value
        });
    },
    upLoad_1: function() {
        var a = this, e = t.getNetAddresss(a.data.uploadUrl);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                var o = t.tempFilePaths;
                console.log(o);
                var s = o[0];
                wx.uploadFile({
                    url: e,
                    filePath: s,
                    name: "file",
                    success: function(t) {
                        var e = JSON.parse(t.data);
                        1 == e.result ? a.setData({
                            "form.thumb": e.data.img_url
                        }) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    upLoad_2: function() {
        var t = this;
        wx.chooseImage({
            count: 9,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                console.log(a.tempFilePaths), t.unload({
                    tempFilePaths: a.tempFilePaths
                }, "1");
            }
        });
    },
    upLoad_3: function() {
        var a = this, e = t.getNetAddresss(a.data.uploadUrl);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                var o = t.tempFilePaths;
                console.log(o);
                var s = o[0];
                wx.uploadFile({
                    url: e,
                    filePath: s,
                    name: "file",
                    success: function(t) {
                        var e = JSON.parse(t.data);
                        1 == e.result ? a.setData({
                            "form.content": e.data.img_url
                        }) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    unload: function(a, e) {
        var o = t.getNetAddresss(this.data.uploadUrl), s = this, i = a.i ? a.i : 0, n = a.success ? a.success : 0, r = a.fail ? a.fail : 0;
        wx.uploadFile({
            url: o,
            filePath: a.tempFilePaths[i],
            name: "file",
            formData: null,
            success: function(t) {
                var a = JSON.parse(t.data);
                s.setData({
                    "form.thumb_url": s.data.form.thumb_url.concat(a.data.img_url)
                }), console.log(s.data.form.thumb_url);
            },
            fail: function(t) {
                r++;
            },
            complete: function(t) {
                ++i == a.tempFilePaths.length ? (console.log("执行完毕"), console.log("成功：" + n + " 失败：" + r)) : (a.i = i, 
                a.success = n, a.fail = r, s.unload(a, e));
            }
        });
    },
    getJson: function() {
        var a = this, e = t.getNetAddresss("plugin.auction.api.index.getAuctionData");
        t._getNetWork({
            url: e,
            data: {
                art: "getGoodsCategory"
            },
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    for (var o = 0; o < e.data.getGoodsCategory.length; o++) {
                        a.data.sectionOptions.push({
                            id: e.data.getGoodsCategory[o].id,
                            value: e.data.getGoodsCategory[o].id,
                            label: e.data.getGoodsCategory[o].name,
                            children: []
                        });
                        for (var s = 0; s < e.data.getGoodsCategory[o].childrens.length; s++) if (a.data.sectionOptions[o].children.push({
                            id: e.data.getGoodsCategory[o].childrens[s].id,
                            value: e.data.getGoodsCategory[o].childrens[s].id,
                            label: e.data.getGoodsCategory[o].childrens[s].name,
                            childrens: []
                        }), 3 == a.data.cat_level) for (var i = 0; i < e.data.getGoodsCategory[o].childrens[s].childrens.length; i++) a.data.sectionOptions[o].children[s].childrens.push({
                            id: e.data.getGoodsCategory[o].childrens[s].childrens[i].id,
                            value: e.data.getGoodsCategory[o].childrens[s].childrens[i].id,
                            label: e.data.getGoodsCategory[o].childrens[s].childrens[i].name
                        });
                    }
                    a.setData({
                        sectionOptions: a.data.sectionOptions
                    }), console.log(a.data.sectionOptions);
                } else wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    bindChange: function(t) {
        var a = t.detail.value;
        this.setData({
            one: a[0],
            two: a[1],
            "pickerValue[0]": a[0],
            "pickerValue[1]": a[1],
            "pickerValue[2]": a[2]
        });
    },
    _closeDateLw: function() {
        this.setData({
            addressShow: !1
        });
    },
    resultAdd: function() {
        this.data.selectedOptions3.push(this.data.sectionOptions[this.data.pickerValue[0]].id), 
        this.data.sectionOptions[this.data.pickerValue[0]].children[this.data.pickerValue[1]] ? (this.data.selectedOptions3.push(this.data.sectionOptions[this.data.pickerValue[0]].children[this.data.pickerValue[1]].id), 
        this.data.sectionOptions[this.data.pickerValue[0]].children[this.data.pickerValue[1]].childrens[this.data.pickerValue[2]] && this.data.selectedOptions3.push(this.data.sectionOptions[this.data.pickerValue[0]].children[this.data.pickerValue[1]].childrens[this.data.pickerValue[2]].id), 
        console.log(this.data.selectedOptions3), this.setData({
            selectedOptions3: this.data.selectedOptions3,
            addressShow: !1
        })) : (wx.showToast({
            title: "至少要选择二级分类",
            icon: "none",
            duration: 1e3
        }), this.setData({
            addressShow: !1
        }));
    },
    xuanzefenl: function() {
        this.setData({
            addressShow: !0,
            selectedOptions3: []
        });
    },
    nextbox: function() {
        if (t._isTextEmpty(this.data.form.title)) wx.showToast({
            title: "请输入拍品单位",
            icon: "none",
            duration: 1e3
        }); else if (t._isTextEmpty(this.data.form.sku)) wx.showToast({
            title: "请输入拍品单位",
            icon: "none",
            duration: 1e3
        }); else if (this.data.selectedOptions3.length <= 0) wx.showToast({
            title: "请选择商品分类",
            icon: "none",
            duration: 1e3
        }); else if (t._isTextEmpty(this.data.form.thumb)) wx.showToast({
            title: "请上传拍品图片",
            icon: "none",
            duration: 1e3
        }); else if (this.data.checkXy) {
            console.log(this.data.paramArr);
            var a = {
                from: this.data.form,
                param_title: this.data.paramArr.length > 0 ? JSON.stringify(this.data.paramArr.map(function(t) {
                    return t.attrvalue;
                })) : JSON.stringify([]),
                param_value: this.data.paramArr.length > 0 ? JSON.stringify(this.data.paramArr.map(function(t) {
                    return t.attrname;
                })) : JSON.stringify([]),
                category: JSON.stringify([ this.data.selectedOptions3 ])
            };
            console.log(JSON.stringify(a));
            var e = JSON.stringify(a);
            this.data.form.goods_id ? (console.log("是编辑"), wx.navigateTo({
                url: "/packageD/auction/auctioneer-publish/publish_second/publish_second?json=" + e + "&&goods_id=" + this.data.form.goods_id
            })) : (console.log("是发布"), wx.navigateTo({
                url: "/packageD/auction/auctioneer-publish/publish_second/publish_second?json=" + e
            }));
        } else wx.showToast({
            title: "请同意竞拍服务协议",
            icon: "none",
            duration: 1e3
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getAgreement: function() {
        var a = this, e = t.getNetAddresss("plugin.auction.api.index.getAuctionData");
        t._postNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (console.log(e), a.setData({
                    protocol: e.data.getAgreement.protocol,
                    cat_level: e.data.getAgreement.cat_level
                })) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getInfo: function() {
        var a = this, e = t.getNetAddresss("plugin.auction.api.index.getAuctionData"), o = {
            art: "editGoods",
            goods_id: this.data.form.goods_id
        };
        t._getNetWork({
            url: e,
            data: o,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    var o = a.data.paramArr;
                    e.data.editGoods.has_many_params.forEach(function(t, a, e) {
                        var s = {};
                        s.attrvalue = t.value, s.attrname = t.title, o.push(s);
                    }), a.setData({
                        "form.title": e.data.editGoods.title,
                        "form.sku": e.data.editGoods.sku,
                        "form.thumb": e.data.editGoods.thumb,
                        "form.describe": e.data.editGoods.has_one_auction_goods.describe,
                        "form.content": e.data.editGoods.content,
                        "form.thumb_url": e.data.editGoods.thumb_url,
                        "form.stock": e.data.editGoods.stock,
                        paramArr: o,
                        selectedOptions3: e.data.editGoods.has_many_goods_category[0].category_ids.split(",")
                    }), console.log(a.data);
                } else wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});